﻿package newXgame.hall.csuper
{
	import flash.display.Sprite;
	
	import org.dstart.draw.csuper.CSprite;

	public class SuperResizeWindow extends CSprite
	{
		private var sprTopLeft:Sprite;			//	左上角影片
		private var sprTopCenter:Sprite;		//	顶部中间影片
		private var sprTopRight:Sprite;			//	右上角影片
		private var sprMiddleLeft:Sprite;		//	左侧中间影片
		private var sprMiddleCenter:Sprite;		//	正中间的影片
		private var sprMiddleRight:Sprite;		//	右侧中间的影片
		private var sprBottomLeft:Sprite;		//	左下角影片
		private var sprBottomCenter:Sprite;		//	底部中间影片
		private var sprBottomRight:Sprite;		//	右下角影片
		
		public function SuperResizeWindow()
		{
			SetSprites();			
		}
		
		//	修改窗口的大小
		public function ChangeSize(ww:Number, hh:Number):void
		{
			if(CheckSprite())
			{
				var minWidth:Number = this.sprTopLeft.width + this.sprTopRight.width + 2;
				var minHeight:Number = this.sprTopLeft.height + this.sprBottomLeft.height + 2;
				
				ww = (ww < minWidth) ? minWidth : ww;
				hh = (hh < minHeight) ? minHeight : hh;
				
				//	顶部一条
				this.sprTopCenter.width = ww - this.sprTopLeft.width - this.sprTopRight.width;
				this.sprTopCenter.x = this.sprTopLeft.x + this.sprTopLeft.width;
				this.sprTopRight.x = this.sprTopCenter.x + this.sprTopCenter.width;
				this.sprTopCenter.y = this.sprTopRight.y = this.sprTopLeft.y;

				//	左侧对象
				this.sprMiddleLeft.x = this.sprTopLeft.x;
				this.sprMiddleLeft.y = this.sprTopLeft.y + this.sprTopLeft.height;
				this.sprMiddleLeft.height = hh - this.sprTopLeft.height - this.sprBottomLeft.height;
				
				//	右侧对象
				this.sprMiddleRight.x = this.sprMiddleLeft.x + (ww - this.sprMiddleRight.width);
				this.sprMiddleRight.y = this.sprTopRight.y + this.sprTopRight.height;
				this.sprMiddleRight.height = hh - this.sprTopRight.height - this.sprBottomRight.height;

				//	底部一条
				this.sprBottomLeft.x = this.sprTopLeft.x;
				this.sprBottomLeft.y = this.sprTopLeft.y + (hh - this.sprBottomLeft.height);
			
				this.sprBottomRight.y = this.sprTopRight.y + (hh - this.sprBottomRight.height);
				this.sprBottomRight.x = this.sprBottomLeft.x + (ww - this.sprBottomRight.width);

				this.sprBottomCenter.x = this.sprBottomLeft.x + this.sprBottomLeft.width;
				this.sprBottomCenter.y = this.sprTopCenter.y + (hh - this.sprBottomCenter.height);
				this.sprBottomCenter.width = ww - this.sprBottomLeft.width - this.sprBottomRight.width;

				//	正中对象
				this.sprMiddleCenter.x = this.sprMiddleLeft.x + this.sprMiddleLeft.width;
				this.sprMiddleCenter.y = this.sprMiddleLeft.y;
				
				this.sprMiddleCenter.width = ww - this.sprMiddleLeft.width - this.sprMiddleRight.width;
				this.sprMiddleCenter.height = hh - this.sprTopCenter.height - this.sprBottomCenter.height;				
				
				this.OpenBitmap(ww + 2, hh + 2);
			}		
		}
		
		private function CheckSprite():Boolean
		{
			if(this.sprTopLeft && this.sprTopCenter && this.sprTopRight
				&& this.sprMiddleCenter && this.sprMiddleLeft && this.sprMiddleRight
				&& this.sprBottomCenter && this.sprBottomLeft && this.sprBottomRight)
			{
				return true;
			}
			
			return false;
		}
		
		//	由子类可以继承的对象
		protected final function SetSprites(	topLeft:Sprite = null, topCent:Sprite = null, topRight:Sprite = null,
										midLeft:Sprite = null, midCent:Sprite = null, midRight:Sprite = null,
										btmLeft:Sprite = null, btmCent:Sprite = null, btmRight:Sprite = null):void
		{
			this.sprTopLeft		= (topLeft) ? topLeft : new Sprite();
			this.sprTopCenter	= (topCent) ? topCent: new Sprite();
			this.sprTopRight	= (topRight) ? topRight : new Sprite();
			
			this.sprMiddleLeft		= (midLeft) ? midLeft : new Sprite();
			this.sprMiddleCenter	= (midCent) ? midCent : new Sprite();
			this.sprMiddleRight		= (midRight) ? midRight : new Sprite();
			
			this.sprBottomLeft		= (btmLeft) ? btmLeft : new Sprite();
			this.sprBottomCenter	= (btmCent) ? btmCent : new Sprite();
			this.sprBottomRight		= (btmRight) ? btmRight : new Sprite();  
			
			_root.addChild(sprMiddleCenter);
			_root.addChild(sprTopLeft);
			_root.addChild(sprTopCenter);
			_root.addChild(sprTopRight);
			_root.addChild(sprMiddleLeft);
			_root.addChild(sprMiddleRight);
			_root.addChild(sprBottomLeft);
			_root.addChild(sprBottomCenter);
			_root.addChild(sprBottomRight);

		}
	}
}